// pages/orderManager/orderDetails/orderDetails.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //弹出框是否显示
    showDialog: false,
    //弹出框高度
    phoneNumberpopupWindowsHeight: 0,
    //弹出框弹出高度
    popupWindowsBottomHeight: 0,
    //头像集合
    headPortraitImages: ["../../../images/header.png", "../../../images/header.png","../../../images/header.png"],
    //操作记录
    operationalRecords: ["", "", "", ""],
    //申请记录
    applyRecords:["",""],
    orderItem: [],
    goodInfoResponses: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    let order= JSON.parse(options.orderItem);
    console.log(order);
    that.setData({
      orderItem:order,
      goodInfoResponses: order.wpOrderInfoResponse.goodInfoResponses,
      applyRecords:order.trustExceptionApplyListResponses,
    })
  },

  previewImg: function (event) {
    var that = this;
    var imgs = event.currentTarget.dataset.imgs;
    wx.previewImage({
      current: event.currentTarget.dataset.currentimg,
      urls: imgs,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 多司机电话
  moreDriverPhone: function (e) {
    
    var that = this;
    //只有一个箱子直接打电话
    if (that.data.orderItem.wpOrderInfoResponse.goodInfoResponses.length == 1 && that.data.orderItem.wpOrderInfoResponse.goodInfoResponses[0].containNum == 1) {
      wx.makePhoneCall({
        phoneNumber: that.data.orderItem.wpWayBillResponseList[0].driverPhone
      })
      return;
    }

    //根据有几个司机，计算弹出框高度
    var popupWindowHeight = (that.data.orderItem.wpWayBillResponseList.length > 4 ? 4 : that.data.orderItem.wpWayBillResponseList.length) * 146;
    if (that.data.orderItem.wayBillStatusEnum == 1) {
      popupWindowHeight = popupWindowHeight + 146;
    }

    //根据有几个司机,计算弹出框弹出高度
    var bottomHeight = (app.globalData.screenHeight - popupWindowHeight) / 2


    that.setData({
      phoneNumberpopupWindowsHeight: popupWindowHeight,
      popupWindowsBottomHeight: bottomHeight
    });

    this.setData({
      showDialog: !this.data.showDialog
    });

  },
  /**
    * 控制 pop 的打开关闭
    * 该方法作用有2:
    * 1：点击弹窗以外的位置可消失弹窗
    * 2：用到弹出或者关闭弹窗的业务逻辑时都可调用
    */
  toggleDialog() {

    if (this.data.showDialog) {
      this.setData({
        phoneNumberpopupWindowsHeight: 0,
        popupWindowsBottomHeight: 0
      });
    }

    this.setData({
      showDialog: !this.data.showDialog
    });

  },
  
  //遮罩层的滚动穿透问题
  myCatchTouch: function () {
    console.log('stop user scroll it!');
    return;
  },
  //拨打电话
  tel: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.target.dataset.phone
    })
  },
  //查看详情
  seeDetails: function() {
    wx.navigateTo({
      url: '/pages/goodsInfo/goodsInfo?goodInfoResponses=' + JSON.stringify(this.data.goodInfoResponses)
    })
  }
})